﻿' <summary>
' BeeWit IDE Entorno de desarrollo Visual para php.
' BeeWitPHP IDE es el único entorno de desarrollo para PHP 
' de tipo WYSIWYG (What You See Is What You Get). 
' ¡Ahora si!, aproveche la potencia del lenguaje PHP 
' y desarrolle más rápidamente gracias a la programación 
' intuitiva de BeeWit.
' Copyright © 2010 Dewins Murillo Garcia 
' EMAIL: dewinsmg@gmail.com
' EMAIL: dewins@beewitsoft.com
' Este Programa es Software Libre: usted puede redistribuirlo 
' y/o modificarlo bajo los términos de la Licencia Publica General 
' GNU como es publicada por la Fundacion de Software Libre; 
' en la 3ra versión de la licencia.
' Este programa es distribuido con la esperanza de que sea útil, 
' pero SIN GARANTÍA ALGUNA; sin siquiera la garantía implícita 
' de VALOR COMERCIAL o FORMADO PARA UN PROPÓSITO EN PARTICULAR. 
' Vea la Licencia Publica General GNU para mas detalles.
' Usted debe haber recibido una copia de la Licencia Publica General 
' GNU junto con este programa. Si no, vaya a http://www.beewitsoft.com
' o en http://code.google.com/p/ajax-beewit-php-ide/
' </summary>
' <remarks></remarks>

Public Class clsHTML

    Public WithEvents HTML As HtmlDocument
    Public Browser As WebBrowser
    Public SelectedElement As HtmlElement
    Private OverElement As HtmlElement
    Private TSTag As ToolStrip


    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

    Public Property TSTags() As ToolStrip
        Get
            Return TSTag
        End Get
        Set(ByVal value As ToolStrip)
            TSTag = value
        End Set
    End Property

    Private Sub ListTags(ByVal TargetImage As HtmlElement)
        Me.TSTag.Items.Clear()
        General.Control_Menu.UnactiveTagMenu()
        Do While Not TargetImage Is Nothing
            Dim item As New clsDesignTags
            item.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
            If TargetImage.TagName.ToUpper = "IFRAME" Then
                If TargetImage.Id <> "" Then
                    item.Name = TargetImage.Id
                    item.Text = "&" & TargetImage.Id
                Else
                    item.Name = TargetImage.TagName
                    item.Text = "&" & TargetImage.TagName
                End If
            Else
                item.Name = TargetImage.TagName
                item.Text = "&" & TargetImage.TagName
                General.Control_Menu.ActiveTagMenu(TargetImage.TagName)
            End If

            item.ToolTipText = TargetImage.TagName
            item.Tag = TargetImage.TagName
            item.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            item.TargetImage = TargetImage
            TargetImage = TargetImage.Parent
            Me.TSTag.Items.Add(item)
            Dim itemSeparator As New ToolStripSeparator
            Me.TSTag.Items.Add(itemSeparator)
        Loop
    End Sub

    Public Sub ValidateAttributes(Optional ByRef TargetImage As HtmlElement = Nothing)
        Try
            If Not TargetImage Is Nothing Then
                SelectedElement = TargetImage
            End If
            'If Not TargetImage Is Nothing Then
            '    SelectedElement = TargetImage
            'Else
            '    If Not OverElement Is Nothing Then
            '        If OverElement.TagName = "BODY" Or OverElement.TagName = "HTML" Then
            '            Exit Sub
            '        End If
            '        SelectedElement = OverElement
            '    End If
            'End If

            If Not SelectedElement Is Nothing Then
                If Not SelectedElement.Style Is Nothing Then
                    Dim Styles() As String = SelectedElement.Style.Split(";")
                    For Each Style As String In Styles
                        If Style.ToUpper Like "*WIDTH*" Then
                            Style = Style.Replace("WIDTH:", "").Replace(" ", "")
                            SelectedElement.SetAttribute("width", Style)
                        End If
                        If Style.ToUpper Like "*HEIGHT*" Then
                            Style = Style.Replace("HEIGHT:", "").Replace(" ", "")
                            SelectedElement.SetAttribute("height", Style)
                        End If
                    Next
                End If
                ListTags(SelectedElement)
                General.Control_Properties.LoadAttributes(SelectedElement)
                General.Control_Eventos.LoadEvents(SelectedElement)
            Else
                'frmBeeWit.Text = "nothing"
            End If

        Catch ex As Exception
            If Not ex.Message Like "*80070005*" Then
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Seleccionando")
            End If

        End Try

    End Sub

    Public Sub SelectOverElement()
        SelectedElement = OverElement
    End Sub

    Private Sub HTML_MouseOver(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles HTML.MouseOver
        OverElement = Me.Browser.Document.GetElementFromPoint(e.ClientMousePosition)
    End Sub

    Public Sub HTML_GetElementOnClientMouse()
        'PointToClient(Cursor.Position)
        'OverElement = Me.Browser.Document.GetElementFromPoint(Cursor.Position)
    End Sub





End Class

